package com.alan.camunda.boot.delegate;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

/**
 * 通过 Java 代理类来终止流程
 */
@Slf4j
@Component("terminateProcessDelegate")
public class TerminateProcessDelegate implements JavaDelegate {
    @Resource
    private RuntimeService runtimeService;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        log.info("通过节点删除/终止流程");
        runtimeService.deleteProcessInstance(delegateExecution.getProcessInstanceId(), "terminate by java delegate");
    }


}
